package app.dao;

import app.entity.QQUser;
import org.apache.ibatis.annotations.*;

/**
 * 注解@Mapper声明当前接口为一个Mapper接口
 * 其中@Select, @Insert，@Delete,@Update分别代表了执行的真实SQL
 **/
@Mapper
public interface DaoQQUser {

    //方法通过openid得到用户信息，@Results注解是结果映射列表，@Result中property是User类的属性名，column是数据库表的字段名
    @Results({
            @Result(property = "uid", column = "id"),
            @Result(property = "openid", column = "openid"),
            @Result(property = "name", column = "name"),
            @Result(property = "image", column = "image"),
            @Result(property = "username", column = "username"),
            @Result(property = "password", column = "password")
    })
    @Select("select * from qqUser where openid = #{openid}")
    QQUser getOpenid(String openid);

    //添加信息
    @Insert("insert into qqUser(uid,  openid, name,  image) values(#{uid}, #{openid}, #{name}, #{image})")
    int insertQQ(QQUser userEntity);

    //修改信息
    @Update("update qqUser set name = #{name}, image = #{image} where openid = #{openid}")
    int updateQQ(QQUser userEntity);
    //QQ授权过之后会给一个openid，通过openid进行查找，如果没有就是首次登陆直接添，如果有先修改信息
}